//---------------------------------------------------------------------------- // File: C3DTools.cpp // Class: C3DTools // Type: 3D API Tools Management // Author: Ken Anderson // Date: 10/26/04 // Desc: Provides a set of tools for the renderers. A function may be directly // linked to a renderer or contain code depending on whether one renderer // supports it or not. OpenGL for example may not support a feature that // Direct3d does, thus a function will directly called Direct3d rather than // contain its own code. // Required headers: // 1. C3DTools.h == Header file containing the class definitions. //---------------------------------------------------------------------------- #include "C3DTools.h" /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: Constructor // Overridden: NA // Permission: Public // Date: 11/28/04 // Type: Common 3D Tools // Desc: Initializes variables and selects the correct renderer. // Parameters: // 1) RendererType RT == Selects the type of renderer for the tools. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DTools::C3DTools(RendererType RT) { //Initialize the renderer pointers. m_pD3D = NULL; m_pOGL = NULL; m_Renderer = RT; switch(RT) { case RENDERER_DIRECT3D: //Allocate memory for the class if((m_pD3D = new D3DTools) == NULL) return; break; case RENDERER_OPENGL: //if((m_pOGL = new OGLTools) == NULL) // return; break; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: Destructor // Overridden: NA // Permission: Public // Date: 11/28/04 // Type: Common 3D Tools // Desc: Cleans up the class by deleting the specific tools. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DTools::~C3DTools() { //Clean's up each renderer's tools, the one not being used //is protected by safe delete from destroying a null pointer. SDELETE(m_pD3D); SDELETE(m_pOGL); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: SetRenderer // Overridden: NA // Permission: Public // Date: 11/28/04 // Type: Common 3D Tools // Desc: Sets the Common 3D system to the specific renderer. // Parameters: // 1) RendererType RT == The type of renderer to use. // Return value: // C3DERR == An error code. Please review C3DTypes.h for more information on each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DTools::SetRenderer(RendererType RT) { //If RT is the same as current renderer, don't waste processes //and exit. if(m_Renderer == RT) return C3D_OK; //Assign renderer. m_Renderer = RT; switch(RT) { case RENDERER_DIRECT3D: //Destroy and clean up the OpenGL Renderer. SDELETE(m_pOGL); //Allocate memory for the direct3d class. if((m_pD3D = new D3DTools) == NULL) return C3DERR_OUTOFMEM; break; case RENDERER_OPENGL: //Destory & clean pu the Direct3d Renderer. SDELETE(m_pD3D); //Allocate memory for the OpenGL class. //if((m_OGL = new OGLTools) == NULL) // return C3DERR_OUTOFMEM; default: return C3DERR_NA; } return C3D_OK; } //////////////////////////////////////////////////////////////////////////////////////////////////////// // // 2D VECTOR MANAGEMENT TOOLS // //////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector2 // Name: Vec2Minimize // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Minimizes the 2d vectors by returning a 2d vector that has the lowest values of the two parameters. // Parameters: // 1) C3DVector2& rOut == A reference to a combined 2d vector. // 2) const C3DVector2& rV1 == A reference to the first 2d vector. // 3) const C3DVector2& rV2 == A reference to the second 2d vector. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec2Minimize(C3DVector2& rOut, const C3DVector2& rV1, const C3DVector2& rV2) { rOut.x = (rV1.x < rV2.x) ? rV1.x : rV2.x; rOut.y = (rV1.y < rV2.y) ? rV1.y : rV2.y; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector2 // Name: Vec2Maximize // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Maximizes the 2d vectors by returning a 2d vector that has the highest values of the two parameters. // Parameters: // 1) C3DVector2& rOut == A reference to a combined 2d vector. // 2) const C3DVector2& rV1 == A reference to the first 2d vector. // 3) const C3DVector2& rV2 == A reference to the second 2d vector. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec2Maximize(C3DVector2& rOut, const C3DVector2& rV1, const C3DVector2& rV2) { rOut.x = (rV1.x > rV2.x) ? rV1.x : rV2.x; rOut.y = (rV1.y > rV2.y) ? rV1.y : rV2.y; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector2 // Name: Vec2Lerp // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Performs a linear Interpolation upon the two vectors returning the product. // Parameters: // 1) C3DVector2& rOut == A reference to a combined 2d vector. // 2) const C3DVector2& rV1 == A reference to the first 2d vector. // 3) const C3DVector2& rV2 == A reference to the second 2d vector. // 4) float s == Amplitude of the vector to scale. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec2Lerp(C3DVector2& rOut, const C3DVector2& rV1, const C3DVector2& rV2, float s) { rOut.x = rV1.x + s * (rV2.x - rV1.x); rOut.y = rV1.y + s * (rV2.y - rV1.y); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector2 // Name: Vec2CCW // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Calculates the z component of the two 2d vectors in a counter-clockwise manner. // Parameters: // 1) const C3DVector2& rV1 == A reference to the first 2d vector. // 2) const C3DVector2& rV2 == A reference to the second 2d vector. // Return value: // float == Value of the z component. ////////////////////////////////////////////////////////////////////////////////////////////////////// float C3DTools::Vec2CCW(const C3DVector2& rV1, const C3DVector2& rV2) { return ((rV1.x * rV2.y) - (rV1.y * rV2.x)); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector2 // Name: Vec2Dot // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Returns dot product of the two 2d vectors. // Parameters: // 1) const C3DVector2& rV1 == A reference to the vector1 to calculate. // 2) const C3DVector2& rV2 == A reference to the vector2 to calculate. // Return value: // float == Value of the length squared. ////////////////////////////////////////////////////////////////////////////////////////////////////// float C3DTools::Vec2Dot(const C3DVector2& rV1, const C3DVector2& rV2) { return ((rV1.x * rV2.x) + (rV1.y * rV2.y)); } //////////////////////////////////////////////////////////////////////////////////////////////////////// // // 3D VECTOR MANAGEMENT TOOLS // ////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector3 // Name: Vec3Minimize // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Minimizes the 3d vectors by returning a 3d vector that has the lowest values of the two parameters. // Parameters: // 1) C3DVector3& rOut == A reference to the combined 3d vector. // 2) const C3DVector3& rV1 == A reference to the first 3d vector. // 3) const C3DVector3& rV3 == A reference to the second 3d vector. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec3Minimize(C3DVector3& rOut, const C3DVector3& rV1, const C3DVector3& rV2) { rOut.x = (rV1.x < rV2.x) ? rV1.x : rV2.x; rOut.y = (rV1.y < rV2.y) ? rV1.y : rV2.y; rOut.z = (rV1.z < rV2.z) ? rV1.z : rV2.z; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector3 // Name: Vec3Maximize // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Maximizes the 3d vectors by returning a 3d vector that has the highest values of the two parameters. // Parameters: // 1) C3DVector3& rOut == A reference to the combined 3d vector. // 2) const C3DVector3& rV1 == A reference to the first 3d vector. // 3) const C3DVector3& rV2 == A reference to the second 3d vector. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec3Maximize(C3DVector3& rOut, const C3DVector3& rV1, const C3DVector3& rV2) { rOut.x = (rV1.x > rV2.x) ? rV1.x : rV2.x; rOut.y = (rV1.y > rV2.y) ? rV1.y : rV2.y; rOut.z = (rV1.z > rV2.z) ? rV1.z : rV2.z; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector3 // Name: Vec3Lerp // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Performs a linear Interpolation upon the two 3d vectors returning the product. // Parameters: // 1) C3DVector3& rOut == A reference to the combined 3d vector. // 2) const C3DVector3& rV1 == A reference to the first 3d vector. // 3) const C3DVector3& rV2 == A reference to the second 3d vector. // 4) float s == Amplitude of the vector to scale. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec3Lerp(C3DVector3& rOut, const C3DVector3& rV1, const C3DVector3& rV2, float s) { rOut.x = (rV1.x + s * (rV2.x - rV1.x)); rOut.y = (rV1.y + s * (rV2.y - rV1.y)); rOut.z = (rV1.z + s * (rV2.z - rV1.z)); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector3 // Name: Vec3Cross // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Calculates the cross product of the two 3d vectors. // Parameters: // 1) const C3DVector3& rV1 == A reference to the first 3d vector. // 2) const C3DVector3& rV2 == A reference to the second 3d vector. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::Vec3Cross(C3DVector3& rOut, const C3DVector3& rV1, const C3DVector3& rV2) { rOut.x = ((rV1.y * rV2.z) - (rV1.z * rV2.y)); rOut.y = ((rV1.z * rV2.x) - (rV1.x * rV2.z)); rOut.z = ((rV1.x * rV2.y) - (rV1.y * rV2.x)); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector3 // Name: Vec3Dot // Overridden: NA // Permission: Public // Date: 10/26/04 // Type: Common 3D Tools // Desc: Returns dot product of the two 3d vectors. // Parameters: // 1) const C3DVector3& rV1 == A reference to vector1 to calculate. // 2) const C3DVector3& rV2 == A reference to vector2 to calculate. // Return value: // float == Value of the length squared. ////////////////////////////////////////////////////////////////////////////////////////////////////// float C3DTools::Vec3Dot(const C3DVector3& rV1, const C3DVector3& rV2) { return ((rV1.x * rV2.x) + (rV1.y * rV2.y) + (rV1.z * rV2.z)); } /* //4-Dimensional Vectors inline float Vec4Dot(C3DVector4* pV1, C3DVector4* pV2); inline C3DVector4* Vec4Minimize(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pV2); inline C3DVector4* Vec4Maximize(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pV2); inline C3DVector4* Vec4Lerp(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pV2, float s); */ /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixZero // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Fills a matrix full of zeros. // Parameters: // 1) C3DMatrix& rOut == A reference to a matrix that will be zeroed. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::MatrixZero(C3DMatrix& rOut) { rOut._11 = 0.0f; rOut._12 = 0.0f; rOut._13 = 0.0f; rOut._14 = 0.0f; rOut._21 = 0.0f; rOut._22 = 0.0f; rOut._23 = 0.0f; rOut._24 = 0.0f; rOut._31 = 0.0f; rOut._32 = 0.0f; rOut._33 = 0.0f; rOut._34 = 0.0f; rOut._41 = 0.0f; rOut._42 = 0.0f; rOut._43 = 0.0f; rOut._44 = 0.0f; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixAdd // Overridden: NA // Permission: Public // Date: 11/6/04 // Type: Common 3D Tools // Desc: Addes two Matricies together and returns the results. // Parameters: // 1) C3DMatrix& rOut == A reference to a resulting Matrix. // 2) const C3DMatrix& rM1 == A reference to the first matrix to be added to another. // 3) const C3DMatrix& rM2 == A reference to the second matrix to be added to another. // Return value: NONE ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::MatrixAdd(C3DMatrix& rOut, const C3DMatrix& rM1, const C3DMatrix& rM2) { rOut._11 = rM1._11 + rM2._11; rOut._12 = rM1._12 + rM2._12; rOut._13 = rM1._13 + rM2._13; rOut._14 = rM1._14 + rM2._14; rOut._21 = rM1._21 + rM2._21; rOut._22 = rM1._22 + rM2._22; rOut._23 = rM1._23 + rM2._23; rOut._24 = rM1._24 + rM2._24; rOut._31 = rM1._31 + rM2._31; rOut._32 = rM1._32 + rM2._32; rOut._33 = rM1._33 + rM2._33; rOut._34 = rM1._34 + rM2._34; rOut._41 = rM1._41 + rM2._41; rOut._42 = rM1._42 + rM2._42; rOut._43 = rM1._43 + rM2._43; rOut._44 = rM1._44 + rM2._44; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixSubtract // Overridden: NA // Permission: Public // Date: 11/6/04 // Type: Common 3D Tools // Desc: Subtracts two Matricies and returns the results. // Parameters: // 1) C3DMatrix& rOut == A reference to a resulting Matrix. // 2) const C3DMatrix& rM1 == A reference to the first matrix to be subtracted to another. // 3) const C3DMatrix& rM2 == A reference to the second matrix to be subtracted to another. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::MatrixSubtract(C3DMatrix& rOut, const C3DMatrix& rM1, const C3DMatrix& rM2) { rOut._11 = rM1._11 - rM2._11; rOut._12 = rM1._12 - rM2._12; rOut._13 = rM1._13 - rM2._13; rOut._14 = rM1._14 - rM2._14; rOut._21 = rM1._21 - rM2._21; rOut._22 = rM1._22 - rM2._22; rOut._23 = rM1._23 - rM2._23; rOut._24 = rM1._24 - rM2._24; rOut._31 = rM1._31 - rM2._31; rOut._32 = rM1._32 - rM2._32; rOut._33 = rM1._33 - rM2._33; rOut._34 = rM1._34 - rM2._34; rOut._41 = rM1._41 - rM2._41; rOut._42 = rM1._42 - rM2._42; rOut._43 = rM1._43 - rM2._43; rOut._44 = rM1._44 - rM2._44; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixScalar // Overridden: NA // Permission: Public // Date: 11/6/04 // Type: Common 3D Tools // Desc: Performs a scalar multiplication on the provided matrix. // Parameters: // 1) C3DMatrix& rOut == A reference to a resulting Matrix. // 2) const C3DMatrix& rM1 == A reference to the first matrix to be multiplied with the scalar value. // 3) const float fScale == Scalar value to multiply with. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::MatrixScalar(C3DMatrix& rOut, const C3DMatrix& rM1, const float fScale) { rOut._11 = rM1._11 * fScale; rOut._12 = rM1._12 * fScale; rOut._13 = rM1._13 * fScale; rOut._14 = rM1._14 * fScale; rOut._21 = rM1._21 * fScale; rOut._22 = rM1._22 * fScale; rOut._23 = rM1._23 * fScale; rOut._24 = rM1._24 * fScale; rOut._31 = rM1._31 * fScale; rOut._32 = rM1._32 * fScale; rOut._33 = rM1._33 * fScale; rOut._34 = rM1._34 * fScale; rOut._41 = rM1._41 * fScale; rOut._42 = rM1._42 * fScale; rOut._43 = rM1._43 * fScale; rOut._44 = rM1._44 * fScale; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixIdentity // Overridden: NA // Permission: Public // Date: 10/28/04 // Type: Common 3D Tools // Desc: Creates a Identity Matrix. // Parameters: // 1) C3DMatrix& rMatrix == A reference to a matrix that will be given an identity. // Return value: ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DTools::MatrixIdentity(C3DMatrix& rMatrix) { rMatrix._11 = 1.0f; rMatrix._12 = 0.0f; rMatrix._13 = 0.0f; rMatrix._14 = 0.0f; rMatrix._21 = 0.0f; rMatrix._22 = 1.0f; rMatrix._23 = 0.0f; rMatrix._24 = 0.0f; rMatrix._31 = 0.0f; rMatrix._32 = 0.0f; rMatrix._33 = 1.0f; rMatrix._34 = 0.0f; rMatrix._41 = 0.0f; rMatrix._42 = 0.0f; rMatrix._43 = 0.0f; rMatrix._44 = 1.0f; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixIsIdentity // Overridden: NA // Permission: Public // Date: 11/06/04 // Type: Common 3D Tools // Desc: Checks the matrix and returns true if it is an identity. // Parameters: // 1) C3DMatrix& rMatrix == A reference to a matrix that maybe an identity. // Return value: // bool == Returns true if the Matrix is an identity. ////////////////////////////////////////////////////////////////////////////////////////////////////// bool C3DTools::MatrixIsIdentity(const C3DMatrix& rMatrix) { return ((rMatrix._11 == 1.0f) && (rMatrix._22 == 1.0f) && (rMatrix._33 == 1.0f) && (rMatrix._44 == 1.0f)); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixInverse // Overridden: NA // Permission: Public // Date: 10/31/04 // Type: Common 3D Tools // Desc: Creates an inverse matrix based on the determinant and the submatrix. // Parameters: // 1) C3DMatrix* pMatrix == Inverse Matrix. // 2) float* pfDeterminant == Determinant of the inverse. // 3) C3DMatrix* pM == Matrix to inverse. // Return value: // C3DMatrix* pMatrix == Inverse Matrix. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixInverse(C3DMatrix* pMatrix, float* pfDeterminant, const C3DMatrix* pM) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixInverse(pMatrix, pfDeterminant, pM); case RENDERER_OPENGL: //return m_OGL->MatrixInverse(pMatrix, pfDeterminant, pM); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixDeterminant // Overridden: NA // Permission: Public // Date: 10/31/04 // Type: Common 3D Tools // Desc: Generates a determinant for the matrix. // Parameters: // 1) const C3DMatrix* pMatrix == Matrix the determinant is being devised from. // Return value: // float == Determinant value. ////////////////////////////////////////////////////////////////////////////////////////////////////// float C3DTools::MatrixDeterminant(const C3DMatrix* pMatrix) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixDeterminant(pMatrix); case RENDERER_OPENGL: //return m_OGL->MatrixDeterminant(pMatrix); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixRotationX // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Rotates a Matrix along the x-axis. // Parameters: // 1) C3DMatrix* pMatrix == Matrix to rotate. // 2) float fAngle == Angle to rotate matrix. // Return value: // C3DMatrix* pMatrix == Matrix to rotate ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixRotationX(C3DMatrix* pMatrix, float fAngle) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixRotationX(pMatrix, fAngle); case RENDERER_OPENGL: //return m_OGL->MatrixRotationX(pMatrix, fAngle); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixRotationY // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Rotates a Matrix along the y-axis. // Parameters: // 1) C3DMatrix* pMatrix == Matrix to rotate. // 2) float fAngle == Angle to rotate matrix. // Return value: // C3DMatrix* pMatrix == Matrix to rotate ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixRotationY(C3DMatrix* pMatrix, float fAngle) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixRotationY(pMatrix, fAngle); case RENDERER_OPENGL: //return m_OGL->MatrixRotationY(pMatrix, fAngle); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixRotationZ // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Rotates a Matrix along the z-axis. // Parameters: // 1) C3DMatrix* pMatrix == Matrix to rotate. // 2) float fAngle == Angle to rotate matrix. // Return value: // C3DMatrix* pMatrix == Matrix to rotate ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixRotationZ(C3DMatrix* pMatrix, float fAngle) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixRotationZ(pMatrix, fAngle); case RENDERER_OPENGL: //return m_OGL->MatrixRotationZ(pMatrix, fAngle); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixTranslation // Overridden: NA // Permission: Public // Date: 2/26/05 // Type: Common 3D Tools // Desc: Translates a Matrix along any of the provided axes. // Parameters: // 1) C3DMatrix* pMatrix == Matrix to translate. // 2) float x == x-axis. // 3) float y == y-axis. // 4) float z == z-axis. // Return value: // C3DMatrix* pMatrix == Matrix to translate. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixTranslation(C3DMatrix* pMatrix, float x, float y, float z) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixTranslation(pMatrix,x,y,z); case RENDERER_OPENGL: //return m_OGL->MatrixTranslation(pMatrix,x,y,z); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixScaling // Overridden: NA // Permission: Public // Date: 2/26/05 // Type: Common 3D Tools // Desc: Scales a Matrix along any of the provided axes. // Parameters: // 1) C3DMatrix* pMatrix == Matrix to scale. // 2) float x == x-axis. // 3) float y == y-axis. // 4) float z == z-axis. // Return value: // C3DMatrix* pMatrix == Matrix to scale. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixScaling(C3DMatrix* pMatrix, float x, float y, float z) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixScaling(pMatrix, x, y, z); case RENDERER_OPENGL: //return m_OGL->MatrixScaling(pMatrix,x,y,z); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixLookAtLH // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Creates a Matrix based on the left handed look at projection. // Parameters: // 1) C3DMatrix* pMatrix == Resulting Matrix. // 2) C3DVector3* pEye == 3D Vector describing the eye location or where the camera is looking at. // 3) C3DVector3* pAt == 3D Vector describing the location of the camera. // 4) C3DVector3* pUp == 3D Vector describing the up vector of the camera. // Return value: // C3DMatrix* pMatrix == Resulting Matrix. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixLookAtLH(C3DMatrix* pMatrix, C3DVector3* pEye, C3DVector3* pAt, C3DVector3* pUp) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixLookAtLH(pMatrix, pEye, pAt, pUp); case RENDERER_OPENGL: //return m_OGL->MatrixLookAtLH(pMatrix, pEye, pAt, pUp); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixLookAtRH // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Creates a Matrix based on the right handed look at projection. // Parameters: // 1) C3DMatrix* pMatrix == Resulting Matrix. // 2) C3DVector3* pEye == 3D Vector describing the eye location or where the camera is looking at. // 3) C3DVector3* pAt == 3D Vector describing the location of the camera. // 4) C3DVector3* pUp == 3D Vector describing the up vector of the camera. // Return value: // C3DMatrix* pMatrix == Resulting Matrix. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixLookAtRH(C3DMatrix* pMatrix, C3DVector3* pEye, C3DVector3* pAt, C3DVector3* pUp) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixLookAtLH(pMatrix, pEye, pAt, pUp); case RENDERER_OPENGL: //return m_OGL->MatrixLookAtLH(pMatrix, pEye, pAt, pUp); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixPerspectiveFovLH // Overridden: NA // Permission: Public // Date: 1/9/05 // Type: Common 3D Tools // Desc: Creates a Left-Handed Perspective matrix. // Parameters: // 1) C3DMatrix* pMatrix == Resulting Matrix. // 2) float fFOV == A float value describing the Field Of View. // 3) float fAspect == A float value describing the aspect ratio of the view. // 4) float fNear == A float value describing the near clipping range. // 5) float fFar == A float value describing the far clipping range. // Return value: // C3DMatrix* pMatrix == Resulting Matrix. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixPerspectiveFovLH(C3DMatrix* pMatrix, float fFOV, float fAspect, float fNear, float fFar) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixPerspectiveFovLH(pMatrix, fFOV, fAspect, fNear, fFar); case RENDERER_OPENGL: //return m_OGL->MatrixPerspectiveFovLH(pMatrix, fFOV, fAspect, fNear, fFar); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixPerspectiveFovRH // Overridden: NA // Permission: Public // Date: 1/9/05 // Type: Common 3D Tools // Desc: Creates a Right-Handed Perspective matrix. // Parameters: // 1) C3DMatrix* pMatrix == Resulting Matrix. // 2) float fFOV == A float value describing the Field Of View. // 3) float fAspect == A float value describing the aspect ratio of the view. // 4) float fNear == A float value describing the near clipping range. // 5) float fFar == A float value describing the far clipping range. // Return value: // C3DMatrix* pMatrix == Resulting Matrix. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixPerspectiveFovRH(C3DMatrix* pMatrix, float fFOV, float fAspect, float fNear, float fFar) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixPerspectiveFovRH(pMatrix, fFOV, fAspect, fNear, fFar); case RENDERER_OPENGL: //return m_OGL->MatrixPerspectiveFovRH(pMatrix, fFOV, fAspect, fNear, fFar); return NULL; default: return NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DTools // Name: MatrixMultiply // Overridden: NA // Permission: Public // Date: 11/7/04 // Type: Common 3D Tools // Desc: Multiplies two matrices together. // Parameters: // 1) C3DMatrix* pMatrix == Resulting Matrix. // 2) const C3DMatrix* pM1 == First Matrix to multiply. // 3) const C3DMatrix* pM2 == Second Matrix to multiply. // Return value: // C3DMatrix* pMatrix == Resulting Matrix. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DMatrix* C3DTools::MatrixMultiply(C3DMatrix* pMatrix, const C3DMatrix* pM1, const C3DMatrix* pM2) { //Check the renderer type. switch(m_Renderer) { case RENDERER_DIRECT3D: return m_pD3D->MatrixMultiply(pMatrix, pM1, pM2); case RENDERER_OPENGL: //return m_OGL->MatrixMultiply(pMatrix, pM1, pM2); return NULL; default: return NULL; } } C3DMatrix* C3DTools::DMTCM(C3DMatrix* pM1, D3DXMATRIX* pM2) { if(m_pD3D != NULL) return m_pD3D->DMTCM(pM1, pM2); else return NULL; } D3DXMATRIX* C3DTools::CMTDM(D3DXMATRIX* pM1, const C3DMatrix* pM2) { if(m_pD3D != NULL) return m_pD3D->CMTDM(pM1, pM2); else return NULL; } /* //Renderer Specific tools inline C3DVector2* Vec2BaryCentric(C3DVector2* pOut, const C3DVector2* pV1, const C3DVector2* pV2, const C3DVector2* pV3, float f, float g); inline C3DVector2* Vec2CatmullRom(C3DVector2* pOut, const C3DVector2* pV1, const C3DVector2* pV2, const C3DVector2* pV3, const C3DVector2* pV4, float s); inline C3DVector2* Vec2Hermite(C3DVector2* pOut, const C3DVector2* pV1, const C3DVector2* pT1, const C3DVector2* pV2, const C3DVector2* pT2, float s); inline C3DVector4* Vec2Transform(C3DVector4** pOut, const C3DVector2* pV, const C3DMatrix* pM); inline C3DVector4* Vec2TransformCoord(C3DVector2* pOut, const C3DVector2* pV, const C3DMatrix* pM); inline C3DVector4* Vec2TransformNormal(C3DVector2* pOut, const C3DVector2* pV, const C3DMatrix* pM); inline C3DVector3* Vec3BaryCentric(C3DVector3* pOut, const C3DVector3* pV1, const C3DVector3* pV2, const C3DVector3* pV3, float f, float g); inline C3DVector3* Vec3CatmullRom(C3DVector3* pOut, const C3DVector3* pV1, const C3DVector3* pV2, const C3DVector3* pV3, const C3DVector3* pV4, float s); inline C3DVector3* Vec3Hermite(C3DVector3* pOut, const C3DVector3* pV1, const C3DVector3* pT1, const C3DVector3* pV2, const C3DVector3* pT2, float s); //inline C3DVector3* Vec3Project(C3DVector3* pOut, const C3DVector3* pV, inline C3DVector4* Vec3Transform(C3DVector4** pOut, const C3DVector3* pV, const C3DMatrix* pM); inline C3DVector4* Vec3TransformCoord(C3DVector3* pOut, const C3DVector3* pV, const C3DMatrix* pM); inline C3DVector4* Vec3TransformNormal(C3DVector3* pOut, const C3DVector3* pV, const C3DMatrix* pM); //inline C3DVector3* Vec3Unproject inline C3DVector4* Vec4BaryCentric(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pV2, const C3DVector4* pV3, float f, float g); inline C3DVector4* Vec4CatmullRom(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pV2, const C3DVector4* pV3, const C3DVector2* pV4, float s); inline C3DVector4* Vec4Cross(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pV2, const C3DVector4* pV3); inline C3DVector4* Vec4Hermite(C3DVector4* pOut, const C3DVector4* pV1, const C3DVector4* pT1, const C3DVector4* pV2, const C3DVector4* pT2, float s); inline C3DVector4* Vec4Transform(C3DVector4* pOut, const C3DVector4* pV, const C3DMatrix* pM); */